
package com.jf.cloud.multishop.feign;

import com.jf.cloud.api.multishop.bo.EsShopDetailBO;
import com.jf.cloud.api.multishop.bo.ShopSimpleBO;
import com.jf.cloud.api.multishop.feign.ShopDetailFeignClient;
import com.jf.cloud.api.multishop.vo.ShopDetailVO;
import com.jf.cloud.api.multishop.vo.ShopUserVO;
import com.jf.cloud.common.order.constant.ShopType;
import com.jf.cloud.common.order.feign.OrderShopDetailFeignClient;
import com.jf.cloud.common.order.vo.ShopInfoInOrderVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.multishop.model.ShopDetail;
import com.jf.cloud.multishop.model.ShopMsgUser;
import com.jf.cloud.multishop.service.ShopDetailService;
import com.jf.cloud.multishop.service.ShopMsgUserService;
import com.jf.cloud.multishop.service.ShopUserService;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Hidden;

import java.util.List;
import java.util.Objects;

/**
 * @author zz
 * @date 2020/11/23
 */
@RestController
@Hidden
public class ShopDetailFeignController implements ShopDetailFeignClient, OrderShopDetailFeignClient {

    @Autowired
    private ShopDetailService shopDetailService;
    @Autowired
    private MapperFacade mapperFacade;
    @Autowired
    private ShopUserService shopUserService;

    @Autowired
    private ShopMsgUserService shopMsgUserService;


    @Override
    public ServerResponseEntity<ShopInfoInOrderVO> getShopInfoInOrderByShopId(Long shopId) {
        ShopDetailVO shopDetail = shopDetailService.getByShopId(shopId);
        ShopInfoInOrderVO shopInfoInOrderVO = new ShopInfoInOrderVO();
        if (Objects.isNull(shopDetail)) {
            shopInfoInOrderVO.setShopName("");
            // 普通店
            shopInfoInOrderVO.setType(ShopType.STOP.value());
            return ServerResponseEntity.success(shopInfoInOrderVO);
        }
        shopInfoInOrderVO.setShopName(shopDetail.getShopName());
        shopInfoInOrderVO.setType(shopDetail.getType());
        return ServerResponseEntity.success(shopInfoInOrderVO);
    }

    @Override
    public ServerResponseEntity<EsShopDetailBO> getShopByShopId(Long shopId) {
        ShopDetailVO shopDetail = shopDetailService.getByShopId(shopId);
        if (Objects.isNull(shopDetail)) {
            return ServerResponseEntity.success(new EsShopDetailBO());
        }
        return ServerResponseEntity.success(mapperFacade.map(shopDetail, EsShopDetailBO.class));
    }

    @Override
    public ServerResponseEntity<ShopDetailVO> getShopDetailByShopId(Long shopId) {
        ShopDetailVO shopDetail = shopDetailService.getByShopId(shopId);
        if (Objects.isNull(shopDetail)) {
            return ServerResponseEntity.success(new ShopDetailVO());
        }
        return ServerResponseEntity.success(shopDetail);
    }

    @Override
    public ServerResponseEntity<Integer> countByMobile(String mobile) {
        return ServerResponseEntity.success(shopDetailService.countByMobile(mobile));
    }

    @Override
    public ServerResponseEntity<List<ShopDetailVO>> listByShopIds(List<Long> shopIds) {
        List<ShopDetail> shopDetail = shopDetailService.listByShopIds(shopIds);
        return ServerResponseEntity.success(mapperFacade.mapAsList(shopDetail, ShopDetailVO.class));
    }

    @Override
    public ServerResponseEntity<EsShopDetailBO> shopExtensionData(Long shopId) {
        return ServerResponseEntity.success(shopDetailService.shopExtensionData(shopId));
    }

    @Override
    public ServerResponseEntity<List<ShopDetailVO>> getShopDetailByShopIdAndShopName(String shopName) {
        return ServerResponseEntity.success(shopDetailService.getShopDetailByShopIdsShopName(null,shopName));
    }

    @Override
    public ServerResponseEntity<List<ShopSimpleBO>> listSimple(ShopSimpleBO shopSimpleBO) {
        return ServerResponseEntity.success(shopDetailService.listSimple(shopSimpleBO));
    }

    @Override
    public ServerResponseEntity<ShopUserVO> getShopUserByShopUserId(Long shopUserId) {
        return ServerResponseEntity.success(mapperFacade.map(shopUserService.getSimpleByUserId(shopUserId), ShopUserVO.class));
    }

    @Override
    public ServerResponseEntity<List<Long>> getShopIdsByShopStatus(Integer shopStatus) {
        return ServerResponseEntity.success(shopDetailService.getShopIdByShopStatus(shopStatus));
    }

    @Override
    public ServerResponseEntity<List<Long>> getShopIdsByLikeShopName(String shopName) {
        return ServerResponseEntity.success(shopDetailService.getShopIdsLikeName(shopName.trim()));
    }

    @Override
    public ServerResponseEntity<List<String>> getShopMsgUserByShopId(Long shopId) {
        return   ServerResponseEntity.success(shopMsgUserService.listByShopId(shopId));
    }
}
